package shujia.day15.bao1;

public class ConsumerThread extends Thread{
    Student student;

    public ConsumerThread(Student student) {
        this.student = student;
    }

    @Override
    public void run() {
//        Student student = new Student();
        while (true){
            synchronized (student){

                /*
                    对于消费者而言，消费数据之前，先看一看数据有没有产生，如果没有产生或上一次产生的数据已经被消费过

                 */
                if(!student.isFlag()){
                    try {
                        student.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                System.out.println(student.getName()+" - "+student.getAge());

                student.setFlag(false);
                student.notify();

            }
        }
    }
}
